<?php

namespace App\Http\Controllers\Api\V2;

use App\Models\XoAnchors;
use Illuminate\Http\Request;
use App\Models\Authorization;
use App\Transformers\NewsTransformer;
use Illuminate\Support\Facades\DB;
use Log;

class XoAnchorsController extends BaseController
{
    /**
     *
     * 获取主播列表
     * @param {Object} Request
     */
    public function index(Request $request)
    {
		$typeName = $request->get('type_name', -1);
		$typeVal = $request->get('type_val', -1);
		if(!in_array($typeName, [-1, 'race', 'hair_type', 'eye_type'])){
			return $this->returnFail('搜索type_name必须是race,hair_type,eye_type其中之一');
		}
        //当前页数 默认1
		$page = $request->get('page', 1);
		//每页的条数
		$perPage = $request->get('perPage', 1);
		//计算每页分页的初始位置
		$offset = ($page * $perPage) - $perPage;
		if($typeName == -1){
			$rows = XoAnchors::orderBy('id', 'desc')->paginate($perPage);
		}else{
			$rows = XoAnchors::where($typeName, $typeVal)->orderBy('id', 'desc')->paginate($perPage);
		}
		
		 //实例化LengthAwarePaginator类，并传入对应的参数
		$dataArray = $rows->toArray();
		$retArr = [];
		foreach($dataArray['data'] as $index => $one){
			
			
		}
		
		
		return $this->returnSuccess($dataArray);
    }
    
    /**
     *
     * 获取通知消息id的详细内容
     * @param {Object} Request
     */
    public function detail(Request $request)
    {
        $id = $request->get('id');
		$detail = XoAnchors::where('id', $id)->first();
    	
    	return $this->returnSuccess($detail);
    }
	
	
	
}
